/**
 * 
 */
package org.project.product.android.pfe.fanta.view;

import org.project.product.android.pfe.fanta.R;
import org.project.product.android.pfe.fanta.domain.Category;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * @author JBromo
 * 
 */
public class CategoryItemView extends LinearLayout {

	private TextView texte;
	private TextView description;
	private TextView numberView;

	public CategoryItemView(Context context, Category item) {
		super(context);
		LayoutInflater.from(context)
		        .inflate(R.layout.category_item, this, true);
		initView();
		reuse(item);
	}

	private void initView() {
		texte = (TextView) findViewById(R.id.category_label);
		description = (TextView) findViewById(R.id.category_description);
		numberView = (TextView) findViewById(R.id.category_number);

	}

	public void reuse(final Category item) {
		texte.setText(item.getName());
		description.setText(item.getDescription());
		int number = item.getNumberItem();
		if (number == 0) {
			numberView.setTextColor(Color.RED);
			numberView.setText("Stocke vide");
			return;
		}
		if (number == 1) {
			numberView.setTextColor(Color.RED);
			numberView.setText("One Product");
			return;
		}

		if (number < 5) {
			numberView.setTextColor(Color.YELLOW);
			numberView.setText(number + " Products");
			return;
		}
		if (number > 5) {
			numberView.setTextColor(Color.GREEN);
			numberView.setText(number + " Products");
			return;
		}

	}
}
